/************************************************************************/
/* UninstallHSSEventLog.sql                                           	*/
/*                                                                    	*/
/* Remove the common tables and stored procedures necessary			  	*/
/* for supporting the HSS EventLog features                           	*/
/*																		*/
/* Copyright HighSpeed-Solutions 2007									*/
/* All Rights Reserved.													*/
/*																		*/
/************************************************************************/

PRINT '----------------------------------------------'
PRINT 'Starting execution of UninstallHSSEventLog.sql'
PRINT '----------------------------------------------'
GO

USE [hsslog]
GO

PRINT '------------------------------------------'
PRINT 'Starting execution of EventLog features   '
PRINT '------------------------------------------'

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Truncate]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Truncate]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Filter]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Filter]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Insert]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Insert]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Update]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Update]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Category_Delete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Category_Delete]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Category_Insert]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Category_Insert]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Category_SelectAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Category_SelectAll]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Category_Update]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Category_Update]
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[vw_hss_EventLog]'))
DROP VIEW [vw_hss_EventLog]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Type_Delete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Type_Delete]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Type_Insert]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Type_Insert]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Type_SelectAll]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Type_SelectAll]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Type_Update]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Type_Update]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_AnyDataInTables]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_AnyDataInTables]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Attachment_Get]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Attachment_Get]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Attachment_Insert]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Attachment_Insert]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Attachment_Set]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_EventLog_Attachment_Set]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Attachments]') AND type in (N'U'))
DROP TABLE [hss_EventLog_Attachments]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Categories]') AND type in (N'U'))
DROP TABLE [hss_EventLog_Categories]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog_Types]') AND type in (N'U'))
DROP TABLE [hss_EventLog_Types]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_EventLog]') AND type in (N'U'))
DROP TABLE [hss_EventLog]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_GetNullable]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_GetNullable]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_GetParameters]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_GetParameters]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_GetSQLMajorVersion]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_GetSQLMajorVersion]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[hss_GetStoredProcedures]') AND type in (N'P', N'PC'))
DROP PROCEDURE [hss_GetStoredProcedures]
GO


PRINT '------------------------------------------'
PRINT 'Completed execution of EventLog features'
PRINT '------------------------------------------'

-- Drop Extended Property indicating HSS CORE is installed in the current database
IF EXISTS(SELECT value FROM ::fn_listextendedproperty 
('hsslog4', null, null, null, null, null, null))
BEGIN
	exec sys.sp_dropextendedproperty 'hsslog4'
END
GO

USE [master]
GO

PRINT '-----------------------------------------------'
PRINT 'Completed execution of UninstallHSSEventLog.sql'
PRINT '-----------------------------------------------'